//
//  MineViewController.m
//  MyvIEW
//
//  Created by Macbook on 27/7/17.
//  Copyright © 2017年 huyu. All rights reserved.
//

#import "MineViewController.h"
#import "UIButton+LT.h"
#import "RaffleTableController.h"
#import "RedrRecordTableController.h"
#import "MineSetViewController.h"
#import "SettingViewController.h"
#import "AboutController.h"
#import "ShopViewController.h"
#import "YOrderViewController.h"
#import "CertificationShopViewController.h"
#import "GuanzhuPerController.h"
#import "ActivityViewController.h"
#import "CardViewController.h"
@interface MineViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray* arr1;
    NSArray* arr2;
    
    NSMutableArray*nsarr1;
    NSMutableArray*nsarr2;
    
    NSArray* arr3;
    NSArray* arr4;
    
    NSString *money;
    
}
//头像
@property (weak, nonatomic) IBOutlet UIImageView *PhotoImg;
//商家描述
@property (weak, nonatomic) IBOutlet UILabel *DesLab;
//商家口号
@property (weak, nonatomic) IBOutlet UILabel *KouHaoLab;
//商家手机号
@property (weak, nonatomic) IBOutlet UILabel *MobLab;

//商家地址
@property (weak, nonatomic) IBOutlet UILabel *LocationLab;

@property (weak, nonatomic) IBOutlet UITableView *MineTabView;
@property(nonatomic,strong)UILabel* RecommendedLab;
@property(nonatomic,strong)UILabel* TabMobLab;
@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的";
    [UIButton backButton:self.navigationItem Col:self];
    arr1 = @[@"我的余额",@"店铺_18--@2x",@"认证_18--@2x",@"icon_timecard_",@"香草邦_18--@2x",@"客服_18--@2x",@"设置_18--@2x"];
    
    nsarr1 = [[NSMutableArray alloc]init];
    
    for (int i =0; i<arr1.count; i++)
    {
        UIImage* image1 = [UIImage imageNamed:arr1[i]];
        [nsarr1 addObject:image1];
    }
    
   
    
    arr3 = @[@"账户余额",@"店铺设置",@"安全认证",@"我的工卡",@"关于香草邦",@"我的关注",@"设置"];
   
    _MineTabView.backgroundColor = colorf7f7f7;
    

}
-(void)viewWillAppear:(BOOL)animated{
    [self questData];
}
-(void)questData{
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    NSString *uid = [defaults objectForKey:@"shop_guid"];
    NSString *url = [NSString stringWithFormat:@"%@shop/selfInfos?shop_guid=%@",ServiceURL2,uid];
    [YBRequestManager GET:url finished:^(NSData *data) {
        NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSArray *str11 = dict[@"data"];
        NSLog(@"dict==%@",dict);
        NSDictionary *dic =  str11[0];
//        NSInteger a = dic[@"money"];
        money = [NSString stringWithFormat:@"%@元",dic[@"money"]];
        _MobLab.text = [NSString stringWithFormat:@"联系方式:%@",dic[@"mobile"]];
        _KouHaoLab.text = [NSString stringWithFormat:@"%@",dic[@"summary"]];
        if ([dic[@"name"] isEqualToString:@""]) {
        _DesLab.text = [NSString stringWithFormat:@"请在店铺认证设置名称"];

        }else{
        _DesLab.text = [NSString stringWithFormat:@"%@",dic[@"name"]];
        }
        _PhotoImg.userInteractionEnabled = YES;
        _PhotoImg.clipsToBounds = YES;
        _PhotoImg.layer.cornerRadius = 32;
        _PhotoImg.contentMode = UIViewContentModeScaleAspectFill;

        [_PhotoImg sd_setImageWithURL:[NSURL URLWithString:dic[@"head_image"]] placeholderImage:[UIImage imageNamed:@"我的_03.png"]];
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setObject:dic[@"head_image"] forKey:@"head_image"];
        [userDefaults setObject:dic[@"summary"] forKey:@"summary"];
        [userDefaults setObject:dic[@"name"] forKey:@"name"];
        [userDefaults setObject:dic[@"city"] forKey:@"city"];

        [self.MineTabView reloadData];
   
        
    } failed:^(NSString *error) {
        
    }];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return 7;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* str = @"mine";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
 
        cell.imageView.image =nsarr1[indexPath.row];
        cell.textLabel.text = arr3[indexPath.row];
        
        if (indexPath.row==0) {
            _RecommendedLab = [[UILabel alloc]init];
            _RecommendedLab.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-22-100,10 ,100, 30);
            _RecommendedLab.text = money;
            _RecommendedLab.textAlignment = NSTextAlignmentRight;
            _RecommendedLab.textColor = [UIColor blackColor];
            [cell addSubview:_RecommendedLab];
        }
        else
        {
            cell.accessoryType = UITableViewCellFocusStyleCustom;

       
        }
    
 
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return 0;
    }
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 10)];
    headerView.backgroundColor =colordg;
    return headerView;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
    

    
        if (indexPath.row==6) {

            SettingViewController* mineSet = [[SettingViewController alloc]init];
            [self.navigationController pushViewController:mineSet animated:YES];

        }else if (indexPath.row==4){
            AboutController* mineSet = [[AboutController alloc]init];
            [self.navigationController pushViewController:mineSet animated:YES];

        }else if (indexPath.row==3){
            CardViewController* mineSet = [[CardViewController alloc]init];
            [self.navigationController pushViewController:mineSet animated:YES];
            
        }
        else if (indexPath.row==1){
            ShopViewController* mineSet = [[ShopViewController alloc]init];
            [self.navigationController pushViewController:mineSet animated:YES];
            
        }else if (indexPath.row==2){
            CertificationShopViewController* mineSet = [[CertificationShopViewController alloc]init];
            [self.navigationController pushViewController:mineSet animated:YES];
            
        }else if (indexPath.row==5){
            GuanzhuPerController* mineSet = [[GuanzhuPerController alloc]init];
            [self.navigationController pushViewController:mineSet animated:YES];
            
        }
    
}
- (IBAction)MineSetBut:(id)sender {
    MineSetViewController* mineSet = [[MineSetViewController alloc]init];
    [self.navigationController pushViewController:mineSet animated:YES];
    
}
- (IBAction)Mypart:(id)sender {
    ActivityViewController* mineSet = [[ActivityViewController alloc]init];
    [self.navigationController pushViewController:mineSet animated:YES];

}
- (IBAction)RaffleBut:(id)sender
{
    RaffleTableController* RaffVC = [[RaffleTableController alloc]init];
    [self.navigationController pushViewController:RaffVC animated:YES];
}
- (IBAction)RedBaoBut:(id)sender
{
    RedrRecordTableController* RedVC = [[RedrRecordTableController alloc]init];
    [self.navigationController pushViewController:RedVC animated:YES];
}
- (IBAction)AttentionBut:(id)sender {
    
    YOrderViewController* ActivityVC = [[YOrderViewController alloc]init];
    [self.navigationController pushViewController:ActivityVC animated:YES];
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
